package com.ybdz.scanner.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.qmuiteam.qmui.widget.QMUIEmptyView;
import com.ybdz.scanner.R;
import com.ybdz.scanner.adapter.LookDepositAdapter;
import com.ybdz.scanner.base.BaseActivity;
import com.ybdz.scanner.bean.DepositHistoryBean;
import com.ybdz.scanner.event.ObjEvent;
import com.ybdz.scanner.utils.SPUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: LookDepositActivity
 * @author: zhao
 * @Description: 查看入库历史
 * @date 2018/2/26 13:52
 */
public class LookDepositActivity extends BaseActivity {

    @BindView(R.id.ll_back)
    LinearLayout mLlBack;
    @BindView(R.id.home)
    FrameLayout mHome;
    @BindView(R.id.rv)
    RecyclerView mRv;
    @BindView(R.id.back_home)
    Button mBackHome;
    @BindView(R.id.empty)
    QMUIEmptyView mEmpty;

    private List<DepositHistoryBean> mList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        ButterKnife.bind(this);
        mEmpty.show(true);
        initRecycleView();
    }


   /* *//**
     * 接收EventBus传递的数据
     *
     * @param event
     *//*
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void getWeight(ObjEvent event) {
        if (event.getId().equals("depositHistory")) {
            mList = (List<DepositHistoryBean>) event.getObj();
            // TODO: 2018/2/2 入库历史未处理
        }
    }*/

    /**
     * 初始化recycleview
     */
    private void initRecycleView() {
        mRv.setLayoutManager(new LinearLayoutManager(this));
        LookDepositAdapter adapter = new LookDepositAdapter();
        mRv.setAdapter(adapter);
        if (mList.size() == 0) {
            mEmpty.show(false,"暂时没有数据",null,null,null);
        } else {
            adapter.setData(mList);
            mEmpty.hide();
        }

    }

    @OnClick({R.id.ll_back, R.id.home, R.id.back_home})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_back:                  //返回
                finish();
                break;
            case R.id.home:                     //返回首页
                startActivity(new Intent(LookDepositActivity.this, MainActivity.class));
                finish();
                break;
            case R.id.back_home:                //返回首页
                startActivity(new Intent(LookDepositActivity.this, MainActivity.class));
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
